import random

from django.core.management.base import BaseCommand
from django.db import transaction
from django.contrib.auth.models import User

from map.models import *

class Command(BaseCommand):
    help = "Generates references"

    @transaction.commit_on_success
    def handle(self, *args, **options):
        # Country center
        area_content_type_country = AreaContentType.objects.get(name = "Country")
        
        slot_type_assembly = SlotType.objects.get(name = "Assembly place slot")
        slot_place = SlotPlace(
            number = 1, 
            slot_type = slot_type_assembly, 
            area_content_type = area_content_type_country
        )
        slot_place.save()
        
        slot_type_building = SlotType.objects.get(name = "Building slot")
        for place_num in xrange(1, area_content_type_country.child_count):
            slot_place = SlotPlace(
                number = place_num + 1, 
                slot_type = slot_type_building, 
                area_content_type = area_content_type_country
            )
            slot_place.save()

        # Suburb with resource mines
        area_content_type_suburb = AreaContentType.objects.get(name = "Suburb")
        slot_type_resource = SlotType.objects.get(name = "Resource mine slot")
        for place_num in range(area_content_type_suburb.child_count):
            slot_place = SlotPlace(
                number = place_num + 1, 
                slot_type = slot_type_resource, 
                area_content_type = area_content_type_suburb
            )
            slot_place.save()
